<template>
<div class="add-common-user">
    <nav-top title="添加预约用户" :goback="true"></nav-top>
    <van-address-list
      class="val"
      v-model="chosenAddressId"
      :list="list"
      add-button-text="添加预约用户"
      @add="onAdd"
      @edit="onEdit"
      @select="selectOK"
    />
</div>
</template>

<script>
import NavTop from "@/components/nav/navBar";
import axios from 'axios';
import { domain, search } from '../../api';
export default {
  components: {
    NavTop
  },
  data() {
    return {
      chosenAddressId: '1',
      list: [
      ],
    }
  },
  created(){
    axios.get(domain+"/api/old/userinfo/list?offset=0&limit=1000")
    .then((res)=>{
      console.log(res.data)
      let data = res.data.data
      if(res.data.code == 1){
          /*
          var temp = [{
            id:0,
            name:'',
            tel:'',
            address:''
          }]
          */
          var temp = []
        let sex
        for(let i = 0; i < data.length; i++){
          if(data[i].sex == 1){
            sex = "男"
          }else{
            sex = "女"
          }
          this.list.push({
              id :data[i].id,
              name: data[i].name,
              tel:  data[i].tel,
              address: "证件类型："+data[i].card_class+"，证件号："+data[i].card+"，姓："+data[i].name_py+"，名："+data[i].class_name+"，性别："+sex
            })
          temp = data[i].id
          
        }
      }else{
        this.$dialog.alert({ title: '发生错误', message: res.data.err })
        console.log(res.data.err)
      }
    })
    .catch((err)=>{
      this.$dialog.alert({ title: '发生错误', message: err })
      console.log(err)
    })
  },
  methods: {
    selectOK(item,index) {
      console.log(item,index)
      this.$dialog.confirm({
        message: '确认使用“'+item.name+'”进行预约?'
      }).then(() => {
        // on confirm
        this.$cookies.set('product_order_user_info_id', item.id)
        window.location.href = "/product/order"+window.location.search
      }).catch(() => {
        
      });
    },
    onAdd() {
      // Toast('新增地址');
      window.location.href = "/user/add/info"+window.location.search
    },

    onEdit(item, index) {
      // window.location.href = "/user/add/info"+window.location.search+"e"
      this.$dialog.alert({
          title: '暂不可用',
          message: '编辑功能将于近日更新'
        })
    }
  }
}
</script>

<style>
.val{
  margin-top: 58px;
}
</style>